package com.wink_172.library.utils

import android.content.Context
import android.os.Environment
import android.util.Log
import com.wink_172.library.model.Constants.cache_path
import com.wink_172.library.model.Constants.savePath
import org.xutils.x


/**
 *
 * 日志管理工具
 * */
object LogUtil {
    private val TAG = "LogUtil"
    var uploading=false //是否有日志在上传中
    var log_name: String ="未初始化_.txt"     //上传日志的名称
    var save_log_path =""

    fun getCachePath(context: Context): String? {
        var cachePath: String? = ""
        cachePath =
            if (Environment.MEDIA_MOUNTED == Environment.getExternalStorageState() || !Environment.isExternalStorageRemovable()) {
                //外部存储可用
                context.externalCacheDir!!.path
            } else {
                //外部存储不可用
                context.cacheDir.path
            }
        return cachePath
    }


    /**
     * 追加到日志文件
     * */
    fun appendToLog(result: String) {

        val time = System.currentTimeMillis()

        CommonJavaUtils.appendTxtToFile(
            "\n时间：" + DateUtil.longToString(time, DateUtil.FORMAT_TIME) +
                    "\n " + result,
            save_log_path,
            log_name
        )
    }


}